% Copyright (C) 2014-19 Benjamin Born and Johannes Pfeifer 
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% See <http://www.gnu.org/licenses/>.

%% Figure 1 in the paper

clear all
if ~isfolder('Results')
    mkdir('.','Results');
end
load('../data_array_for_regression_stacked_by_variable_CDS_new');
fontsize=8;

figure('Name','Sovereign yield spreads: empirical distribution function')
subplot(2,1,1)
plot(country_group_specific_CDF_end_quarter.spread_value_pooled,country_group_specific_CDF_end_quarter.CDF_value_pooled,'k-',country_group_specific_CDF_end_quarter.spread_value_developed,country_group_specific_CDF_end_quarter.CDF_value_developed,'k-.',country_group_specific_CDF_end_quarter.spread_value_emerging,country_group_specific_CDF_end_quarter.CDF_value_emerging,'k--','LineWidth',1)
axis tight
set(gca,'FontSize',fontsize)
leghandle=legend('Full Sample','Developed','Emerging');
xlabel('Default premium (pps)')
ylabel('Cumulative density')
print('Results/Spread_CDFs','-depsc2')